<template>
  <div>
    <el-col :span="24" class="bg1">
      <div class="grid-content bg-purple">
        <FormPanel ref="formPanel" :list="formList" :cols="1" :labelWidth="120" :isSubmitBtn="false" @formChange="formChangeHandle"/>
      </div>
    </el-col>

    <div class="dialogBottmView">
      <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeMenu('3')">关闭
      </el-button>

    </div>

  </div>
</template>

<script>
import {
  addAssembly,
  getByAssemblyId,
  getByThreeId,
  listRecordNew,
  updateMaintain
} from '@/api/repair/threePacksOfManager/regulationsQueryCDuan';


  import {dictionary} from '@/utils/dictMixin';
  import {isEmpty} from '@/utils/utils';
  import {exportExcelFile} from '@/utils/index';

  export default {
    name: 'detail',
    mixins: [dictionary],
    /*handleType show   活动审核  show-1  索赔审核*/
    props: ['handleType', 'assemblyId'],
    data()
    {
      this.saveData = null;
      return {

        formList: this.createFormList(),
        detailObj: {},
      };
    },
    components: {},
    async mounted()
    {
      let res = await listRecordNew({
        isDeleted: 0,
        pageNum: 1,
        currentPage: 1,
        pageSize: 99999,
        limit: 99999,
      });
      if (res.resultCode === 200) {
        this.formList.find(x=>x.fieldName=='threeNo').itemList = res.data.records.map(y => ({ text: y.threeNo, value: y.threeId }));
      }
      // await this.getData();
    },
    methods: {
      formChangeHandle(val) {
        this.saveData = val;
      },
      //保存
      async saveDialog() {
        let err = this.$refs.formPanel.submitForm();
        if (err) {
          // this.$notify.error({ title: '提示信息', message: '请检查提交数据' });
          return;
        }
        let threeNoELe = this.formList.find(x=>x.fieldName=='threeNo');
        let threeNo = threeNoELe.itemList.find(x=> x.value == threeNoELe.initialValue).text
        this.saveData.threeNo = threeNo;
        this.saveData.threeId = threeNoELe.initialValue;
        let params = Object.assign({}, this.saveData);
        let res = await addAssembly(params);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
        }
        this.loading = false;
      },
      /*根据ID查询*/
      async getData()
      {
        let res = await getByAssemblyId({'id': this.assemblyId});

        if (res.resultCode == 200 && res.success == true)
        {
          let data = isEmpty(res['data']) ? {} : res['data'];

          for (let i in data)
          {
            this.formList.map(x =>
            {
              if (i == x.fieldName)
              {
                x.initialValue = data[i];
              }
            });
          }
        }

      },
      async closeMenu(type)
      {
        this.$emit('close')
      },

      createFormList()
      {

        return [
          {
            type: 'SELECT',
            label: '规则编号',
            fieldName: 'threeNo',
            placeholder: '请选择规则编号...',
            style: {width: '200px'},
            rules: [{required: true, message: '请选择规则编号', trigger: 'change'}],
            itemList: []
          },
          {
            type: 'INPUT',
            label: '总成编号',
            fieldName: 'assemblyCode',
            placeholder: '请输入总成编号...',
            style: {width: '200px'},
            rules: [{required: true, message: '请输入总成编号', trigger: 'change'}],
          },
          {
            type: 'INPUT',
            label: '总成名称',
            fieldName: 'assemblyName',
            placeholder: '请输入总成名称...',
            style: {width: '200px'},
            rules: [{required: true, message: '请输入总成编号', trigger: 'change'}],
          },
          {
            type: 'TEXT_AREA',
            label: '关系描述',
            fieldName: 'remarks',
            placeholder: '请输入关系描述',
            rules: [{required: true, message: '请输入关系描述', trigger: 'change'}],
            initialValue: '',
            style: {width: '400px'},
          }
        ];
      },
    }
  };
</script>

<!--<style scoped lang="less">-->
<!--  .bg1 {-->
<!--    border: 1px solid @borderColor;-->
<!--    border-radius: @borderRadius;-->
<!--    box-shadow: @boxShadow;-->
<!--    padding: @modulePadding;-->
<!--    padding-left: 0;-->
<!--    padding-top: 15px;-->
<!--    padding-bottom: 15px;-->
<!--  }-->

<!--  .bg2 {-->
<!--    margin-top: 10px;-->
<!--    margin-bottom: 10px;-->
<!--  }-->

<!--  .btn {-->
<!--    text-align: center;-->
<!--  }-->

<!--  .btnStyle {-->
<!--    margin-top: 10px;-->
<!--  }-->
<!--</style>-->
